package solver.moves;

import java.util.Random;

import command.Invoker;

import model.IncrementalCostCalculator;
import model.IncrementalValidator;
import model.SolverEnvironment;
import model.Problem;
import model.Solution;

public class SingleRandomProcessToRandomMachineMove extends AbstractMove {

	public SingleRandomProcessToRandomMachineMove(SolverEnvironment env) {
		super(env);
	}

	public boolean performMove(){
		int p_index = getSingleCandiadateProcess();
		int orig_m_index = env.getPotentialSolution().getMachineIdForProcessId(p_index);
		int num = (int)Math.max((getRandom().nextInt(getProblem().M)*0.01*(getRandom().nextInt(10)+1)),1);
		int m = testRandomNoSchedule(p_index, orig_m_index, num);
		if (m!=-1){
			env.getCostCalculator().getProcessMoveToMachineCost(env.getPotentialSolution(),
					p_index, orig_m_index, m);
			makeMove(p_index, orig_m_index, m);
			return true;
		}
		else
			return false;
	}

}
